package p.ithorns.example.statemachine.trans;

import com.alibaba.cola.statemachine.builder.FailCallback;
import com.alibaba.cola.statemachine.exception.TransitionFailException;
import lombok.extern.slf4j.Slf4j;

/**
 * TransFailCallback
 *
 * @author Ht.L
 * @date 2023-09-09 21:51
 * @since 1.0.0
 */
@Slf4j
public class TransFailCallback<S, E, C> implements FailCallback<S,E,C> {

    @Override
    public void onFail(S sourceState, E event, C context) {
        log.warn("当前状态[{}], 不允许执行[{}]事件", sourceState, event);
        throw new TransitionFailException(
                "Cannot fire event [" + event + "] on current state [" + sourceState + "] with context [" + context + "]"
        );
    }

}